home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / bit / src / ulib / hash.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  704b  |  27 lines

  1. /***********************************************************************
  2.  * $Id: hash.c,v 0.51 1993/07/23 22:00:37 zhao Exp $
  3.  *
  4.  *.  Copyright(c) 1993 by T.C. Zhao                                    
  5.  *   All rights reserved.                                              
  6.  *.
  7.  *   Simple hash function
  8.  ***********************************************************************/
  9. #if !defined(lint) && defined(F_ID)
  10. char *id_hash = "$Id: hash.c,v 0.51 1993/07/23 22:00:37 zhao Exp $";
  11. #endif
  12.  
  13. #ifndef HASHMAX
  14. #define HASHMAX ((1 << 12) - 1)
  15. #endif
  16.  
  17. int
  18. hash(register const char *s)
  19. {
  20.     register int val = 0;
  21.  
  22.     while (*s)
  23.         val = 33 * val + *s++;
  24.     return ((val > 0) ? val : -val) % HASHMAX;
  25. }
  26.  
  27.